define(function(require, exports, module) {
  'use strict';

  var $ = require('$');
  var Tips = require('tips');
  var Alert = require('alert');

  var Form = require('../common/form/form');

  new Form({
    container: '#J_Form',
    url: 'userEditPwd',
    customRules: {
      checkPwd: {
        chkpwd: function (e) {
          return e.value.trim() === $('#newPw').val().trim();
        }
      }
    },
    customMessages: {
      checkPwd: {
        chkpwd: '输入的密码和新的密码不一致，请重输！'
      }
    },
    data: {
      groups: [{
        label: '当前密码',
        attrs: {
          type: 'password',
          name: 'oldPw',
          placeholder: '当前密码',
          autofocus: 'autofocus',
          required: 'required',
          maxlength: 50
        }
      }, {
        label: '新的密码',
        attrs: {
          type: 'password',
          id:'newPw',
          name: 'newPw',
          placeholder: '新的密码',
          autofocus: 'autofocus',
          required: 'required',
          maxlength: 50
        }
      }, {
        label: '确认密码',
        attrs: {
          type: 'password',
          name: 'checkPwd',
          placeholder: '确认密码',
          autofocus: 'autofocus',
          chkpwd: 'chkpwd',
          required: 'required',
          maxlength: 50
        }
      }]
    },
    events: {
      done: function() {
        console.log('done');
        new Tips({
          content: '修改成功！'
        });
      },
      fail: function(e, data) {
        new Alert({
          content: (data && data.messages) || '修改异常'
        });
      }
    }
  });
});
